local jiangchi = fk.CreateSkill({
    name = "sj4__jiangchi",
})

Fk:loadTranslationTable{
    ["sj4__jiangchi"] = "将驰",
    [":sj4__jiangchi"] = "准备阶段，你可以令两名角色本回合使用基本牌后翻面，若包含你，你可以摸三张牌或使用一张【杀】。",
    ["#sj4__jiangchi_fan"] = "将驰",
  
    ["#sj4__jiangchi_slash"] = "将驰：你可以使用一张【杀】或取消后摸三张牌",
    
    ["@sj4__jiangchi-turn"] = "将驰",
    ["#sj4__jiangchi"] = "将驰：你可以令两名角色本回合使用基本牌后翻面",
    ["#sj4__jiangchi-ask"] = "将驰：你可以摸三张牌或使用一张【杀】",
    
    ["$sj4__jiangchi1"] = "吾定当身先士卒，振魏武雄风！",
    ["$sj4__jiangchi2"] = "屯粮坚守，待敌纰漏。",
    ["$sj4__jiangchi3"] = "身当矢石，驰骛四方。",
  
}

jiangchi:addEffect(fk.EventPhaseStart, {
    mute = true,
    can_trigger = function(self, event, target ,player, data)
      return player:hasSkill(jiangchi.name) and target == player and player.phase == Player.Start
    end,
    on_cost = function (self, event, target, player, data)
      local room = player.room
      local targets = room:askToChoosePlayers(player,{
        targets = room:getAlivePlayers(),
        min_num = 2,
        max_num = 2,
        prompt = "#sj4__jiangchi",
        skill_name = jiangchi.name
      })
      event:setCostData(self,{targets = targets})
      return #targets > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local targets = event:getCostData(self).targets
      for _, t in ipairs(targets) do
        room:setPlayerMark(t,"@sj4__jiangchi-turn","basic")
      end
      player:broadcastSkillInvoke(jiangchi.name,1)
      room:doIndicate(player,targets)
      room:notifySkillInvoked(player, jiangchi.name,nil,table.map(target,Util.IdMapper))
      if table.contains(targets,player) then
        if room:askToSkillInvoke(player,{skill_name = jiangchi.name, prompt = "#sj4__jiangchi-ask"}) then
          local u = room:askToUseCard(player,{
            pattern = "slash",
            skill_name = "slash", --不可缺少
            prompt = "#sj4__jiangchi_slash",
            cancelable = true,
            extra_data = {bypass_times = true},
          })
          if u then
            player:broadcastSkillInvoke(jiangchi.name,3)
            room:useCard(u)
          else
            player:broadcastSkillInvoke(jiangchi.name,2)
            room:drawCards(player,3,jiangchi.name)
          end
        end
      end
    end,
})

jiangchi:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player == target and player:getMark("@sj4__jiangchi-turn") == "basic" and data.card.type == Card.TypeBasic and not player.dead
  end,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:turnOver()
  end,
})

return jiangchi